// pages/joinUs/joinUs.js  
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    submit: false,
    source_txt: '',
    source: '',
  },
  bindRegionChange: function (e) {
    this.setData({
      region: e.detail.value
    })
  },
  joinUs:function(e){
    var that = this;
    var name = e.detail.value.name;
    var phone = e.detail.value.phone;
    var region = that.data.region;
    
    if(that.data.submit) return;
    if(!wx.getStorageSync('userInfo')){
      wx.navigateTo({
        url: '/pages/welcome/welcome',
      })
      return;
    }
    var pattern = /^1[3456789]\d{9}$/;
    if (!name){
      wx.showToast({
        title: '请输入姓名',
        icon:"none"
      })
    }else if(!pattern.test(phone)){
      wx.showToast({
        title: '请输入正确的手机号',
        icon:"none"
      })
    }else if(!region){
      wx.showToast({
        title: '请选择所在地区',
        icon:"none"
      })
    }else{
      var param = {
        name: name,
        phone: phone,
        company: e.detail.value.company,
        region: region.join(','),
        address: e.detail.value.address,
        source: that.data.source,
        source_text: that.data.source_txt,
      } 
      that.setData({
        submit: !that.data.submit
      })
     app.httpRequest('user/contact', param, 'get', false, function(res){
       wx.showModal({
         content: res.msg,
         showCancel: false,
         success:function(){
           wx.navigateBack({
             delta: 1,
           })
           that.setData({
            submit: !that.data.submit
          })
         }
       })
        app.userBehavior(132,'提交了联系我们表单 --' + that.data.source_txt)
     })

    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var source = options.source || '';
    var source_txt = options.source_txt || '';
    var that = this;
    that.setData({
      source: source,
      source_txt: source_txt,
      user: wx.getStorageSync('userInfo'),
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})